import {RouteData, RouteElement, RouterLoader, RouterMetadata} from "@/config/route/route-types";
import {AnyParams} from "@/common/httptypes";
import {util} from "@/common/util";
import {ApplicationDataSource} from "@/config/route/loader-route-common";

import ROUTER_DATA from './router-cofig.json';

export const dataSource: RouteData = {
    link:[],

    
    layout: JSON.parse(JSON.stringify(ROUTER_DATA)),      //本地路由
}

export class LoaderLocalRouter implements RouterLoader {
    loaderMetadata(): Promise<RouterMetadata> {
        const list: RouteElement[] = []
        const mapping: AnyParams<RouteElement> = {}
        const layout: RouteElement[] = []

        util.Each([...ApplicationDataSource.link, ...dataSource.link], "children", 0, (p, level) => {
            let item = p as RouteElement
            item.layout = false
            list.push(item)
            mapping[item.path] = item
        })

        util.Each([...ApplicationDataSource.layout, ...dataSource.layout], "children", 0, (p, level) => {
            let item = p as RouteElement
            item.layout = true
            list.push(item)
            mapping[item.path] = item
            if (level === 0) {
                layout.push(item)
            }
        })
        return Promise.resolve({enable: true, buttons: [], list, mapping, layout});
    }

}